package gsp420.helloworld;

import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.lang.reflect.Method;

public class JavaToy
{
	static void sleep(int ms){
		try{Thread.sleep(ms);}catch(Exception e){}
	}
	static int random(){
		return (int)(10*Math.random()-5);
	}
	public static void main(String[] args){
		Method[] methods = JavaToy.class.getDeclaredMethods();
		Method m;
		for(int i = 0; i < methods.length; ++i){
			m = methods[i];
			Class[] params = m.getParameterTypes();
			System.out.println(m.getGenericReturnType()+" "+m.getName()+" "+
			params.length+" parameters ");
			for (int j = 0; j < params.length; j++) {
				System.out.println(params[j].getName());
			}
			if(m.getName().equals("sleep")){
				try{
					m.invoke(null, new Object[]{new Integer(5000)});
				}catch(Exception e){}
			}
		}
		Robot r = null;
		try{
			r = new Robot();
		}catch(Exception e){
			System.out.println("Java does not want us toying with Robot.");
			return;
		}
//		String myMessage = "hello world";
		int[] keys = {
				KeyEvent.VK_H,
				KeyEvent.VK_E,
				KeyEvent.VK_L,
				KeyEvent.VK_L,
				KeyEvent.VK_O,
				KeyEvent.VK_SPACE,
				KeyEvent.VK_W,
				KeyEvent.VK_O,
				KeyEvent.VK_R,
				KeyEvent.VK_L,
				KeyEvent.VK_D,
		};
		int pauseDelay = 100;
		int pressDelay = 10;
		for(int i = 0; i < keys.length; ++i){
			r.keyPress(keys[i]);
			sleep(pressDelay);
			r.keyRelease(keys[i]);
			sleep(pauseDelay);
			r.mouseMove(5*i, 5*i);
		}
	}
}
